home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2007 December / PCWKCD1207B.iso / Blogowanie poza sfera / Flock 0.9.1.3 stable / flock-0.9.1.3.en-US.win32.exe / flock / chrome / browser.jar / content / browser / sanitize.js < prev    next >
Text File  |  2007-04-16  |  10KB  |  309 lines

  1. //@line 39 "/cygdrive/K/tinderbuild/src/flock/mozilla/browser/base/content/sanitize.js"
  2.  
  3. function Sanitizer() {}
  4. Sanitizer.prototype = {
  5.   // warning to the caller: this one may raise an exception (e.g. bug #265028)
  6.   clearItem: function (aItemName)
  7.   {
  8.     if (this.items[aItemName].canClear)
  9.       this.items[aItemName].clear();
  10.   },
  11.  
  12.   canClearItem: function (aItemName)
  13.   {
  14.     return this.items[aItemName].canClear;
  15.   },
  16.   
  17.   _prefDomain: "privacy.item.",
  18.   getNameFromPreference: function (aPreferenceName)
  19.   {
  20.     return aPreferenceName.substr(this._prefDomain.length);
  21.   },
  22.   
  23.   /**
  24.    * Deletes privacy sensitive data in a batch, according to user preferences
  25.    *
  26.    * @returns  null if everything's fine;  an object in the form
  27.    *           { itemName: error, ... } on (partial) failure
  28.    */
  29.   sanitize: function ()
  30.   {
  31.     var psvc = Components.classes["@mozilla.org/preferences-service;1"]
  32.                          .getService(Components.interfaces.nsIPrefService);
  33.     var branch = psvc.getBranch(this._prefDomain);
  34.     var errors = null;
  35.     for (var itemName in this.items) {
  36.       var item = this.items[itemName];
  37.       if ("clear" in item && item.canClear && branch.getBoolPref(itemName)) {
  38.         // Some of these clear() may raise exceptions (see bug #265028)
  39.         // to sanitize as much as possible, we catch and store them, 
  40.         // rather than fail fast.
  41.         // Callers should check returned errors and give user feedback
  42.         // about items that could not be sanitized
  43.         try {
  44.           item.clear();
  45.         } catch(er) {
  46.           if (!errors) 
  47.             errors = {};
  48.           errors[itemName] = er;
  49.           dump("Error sanitizing " + itemName + ": " + er + "\n");
  50.         }
  51.       }
  52.     }
  53.     return errors;
  54.   },
  55.   
  56.   items: {
  57.     cache: {
  58.       clear: function ()
  59.       {
  60.         const cc = Components.classes;
  61.         const ci = Components.interfaces;
  62.         var cacheService = cc["@mozilla.org/network/cache-service;1"]
  63.                              .getService(ci.nsICacheService);
  64.         try {
  65.           cacheService.evictEntries(ci.nsICache.STORE_ANYWHERE);
  66.         } catch(er) {}
  67.       },
  68.       
  69.       get canClear()
  70.       {
  71.         return true;
  72.       }
  73.     },
  74.     
  75.     cookies: {
  76.       clear: function ()
  77.       {
  78.         var cookieMgr = Components.classes["@mozilla.org/cookiemanager;1"]
  79.                                   .getService(Components.interfaces.nsICookieManager);
  80.         cookieMgr.removeAll();
  81.       },
  82.       
  83.       get canClear()
  84.       {
  85.         return true;
  86.       }
  87.     },
  88.     
  89.     history: {
  90.       clear: function ()
  91.       {
  92.         var globalHistory = Components.classes["@mozilla.org/browser/global-history;2"]
  93.                                       .getService(Components.interfaces.nsIBrowserHistory);
  94.         globalHistory.removeAllPages();
  95.         
  96.         try {
  97.           var os = Components.classes["@mozilla.org/observer-service;1"]
  98.                              .getService(Components.interfaces.nsIObserverService);
  99.           os.notifyObservers(null, "browser:purge-session-history", "");
  100.         }
  101.         catch (e) { }
  102.  
  103.         // purge Mediabar recent history
  104.         var coop = Components.classes['@flock.com/singleton;1']
  105.                                .getService(Components.interfaces.flockISingleton)
  106.                                .getSingleton('chrome://browser/content/flock/common/load-faves-coop.js')
  107.                                .wrappedJSObject;
  108.         
  109.         var recentRoot = coop.get("urn:media:recent");
  110.         var recentEnum = recentRoot.children.enumerate();
  111.         var elem;
  112.         while (recentEnum.hasMoreElements()) {
  113.           elem = recentEnum.getNext();
  114.           elem.destroy();
  115.         }
  116.       },
  117.       
  118.       get canClear()
  119.       {
  120.         // bug 347231: Always allow clearing history due to dependencies on
  121.         // the browser:purge-session-history notification. (like error console)
  122.         return true;
  123.       }
  124.     },
  125.     
  126.     formdata: {
  127.       clear: function ()
  128.       {
  129.         //Clear undo history of all searchBars
  130.         var windowManager = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService();
  131.         var windowManagerInterface = windowManager.QueryInterface(Components.interfaces.nsIWindowMediator);
  132.         var windows = windowManagerInterface.getEnumerator("navigator:browser");
  133.         while (windows.hasMoreElements()) {
  134.           var searchBar = windows.getNext().document.getElementById("searchbar");
  135.           if (searchBar) {
  136.             searchBar.value = "";
  137.             searchBar.textbox.editor.enableUndo(false);
  138.             searchBar.textbox.editor.enableUndo(true);
  139.           }
  140.         }
  141.  
  142.         var formHistory = Components.classes["@mozilla.org/satchel/form-history;1"]
  143.                                     .getService(Components.interfaces.nsIFormHistory2);
  144.         formHistory.removeAllEntries();
  145.       },
  146.       
  147.       get canClear()
  148.       {
  149.         var formHistory = Components.classes["@mozilla.org/satchel/form-history;1"]
  150.                                     .getService(Components.interfaces.nsIFormHistory2);
  151.         return formHistory.hasEntries;
  152.       }
  153.     },
  154.     
  155.     downloads: {
  156.       clear: function ()
  157.       {
  158.         var dlMgr = Components.classes["@mozilla.org/download-manager;1"]
  159.                               .getService(Components.interfaces.nsIDownloadManager);
  160.         dlMgr.cleanUp();
  161.       },
  162.  
  163.       get canClear()
  164.       {
  165.         var dlMgr = Components.classes["@mozilla.org/download-manager;1"]
  166.                               .getService(Components.interfaces.nsIDownloadManager);
  167.         return dlMgr.canCleanUp;
  168.       }
  169.     },
  170.     
  171.     passwords: {
  172.       clear: function ()
  173.       {
  174.         var pwmgr = Components.classes["@mozilla.org/passwordmanager;1"]
  175.                               .getService(Components.interfaces.nsIPasswordManager);
  176.         var e = pwmgr.enumerator;
  177.         var passwds = [];
  178.         while (e.hasMoreElements()) {
  179.           var passwd = e.getNext().QueryInterface(Components.interfaces.nsIPassword);
  180.           passwds.push(passwd);
  181.         }
  182.         
  183.         for (var i = 0; i < passwds.length; ++i)
  184.           pwmgr.removeUser(passwds[i].host, passwds[i].user);
  185.       },
  186.       
  187.       get canClear()
  188.       {
  189.         var pwmgr = Components.classes["@mozilla.org/passwordmanager;1"]
  190.                               .getService(Components.interfaces.nsIPasswordManager);
  191.         return pwmgr.enumerator.hasMoreElements();
  192.       }
  193.     },
  194.     
  195.     sessions: {
  196.       clear: function ()
  197.       {
  198.         // clear all auth tokens
  199.         var sdr = Components.classes["@mozilla.org/security/sdr;1"]
  200.                             .getService(Components.interfaces.nsISecretDecoderRing);
  201.         sdr.logoutAndTeardown();
  202.  
  203.         // clear plain HTTP auth sessions
  204.         var authMgr = Components.classes['@mozilla.org/network/http-auth-manager;1']
  205.                                 .getService(Components.interfaces.nsIHttpAuthManager);
  206.         authMgr.clearAll();
  207.       },
  208.       
  209.       get canClear()
  210.       {
  211.         return true;
  212.       }
  213.     },
  214.  
  215.     // Added to handle deletion of accounts data in the RDF
  216.     configuredAccounts: {
  217.       clear: function ()
  218.       {
  219.         var acUtils = Components.classes["@flock.com/account-utils;1"]
  220.                             .getService(Components.interfaces.flockIAccountUtils);
  221.  
  222.         acUtils.removeAllAccounts();
  223.       },
  224.  
  225.       get canClear()
  226.       {
  227.         var acUtils = Components.classes["@flock.com/account-utils;1"]
  228.                             .getService(Components.interfaces.flockIAccountUtils);
  229.  
  230.         return acUtils.doAccountsExist();
  231.       }
  232.     }
  233.   }
  234. };
  235.  
  236.  
  237.  
  238. // "Static" members
  239. Sanitizer.prefDomain          = "privacy.sanitize.";
  240. Sanitizer.prefPrompt          = "promptOnSanitize";
  241. Sanitizer.prefShutdown        = "sanitizeOnShutdown";
  242. Sanitizer.prefDidShutdown     = "didShutdownSanitize";
  243.  
  244. Sanitizer._prefs = null;
  245. Sanitizer.__defineGetter__("prefs", function() 
  246. {
  247.   return Sanitizer._prefs ? Sanitizer._prefs
  248.     : Sanitizer._prefs = Components.classes["@mozilla.org/preferences-service;1"]
  249.                          .getService(Components.interfaces.nsIPrefService)
  250.                          .getBranch(Sanitizer.prefDomain);
  251. });
  252.  
  253. // Shows sanitization UI
  254. Sanitizer.showUI = function(aParentWindow) 
  255. {
  256.   var ww = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
  257.                      .getService(Components.interfaces.nsIWindowWatcher);
  258. //@line 298 "/cygdrive/K/tinderbuild/src/flock/mozilla/browser/base/content/sanitize.js"
  259.   ww.openWindow(aParentWindow,
  260. //@line 300 "/cygdrive/K/tinderbuild/src/flock/mozilla/browser/base/content/sanitize.js"
  261.                 "chrome://browser/content/sanitize.xul",
  262.                 "Sanitize",
  263.                 "chrome,titlebar,centerscreen,modal",
  264.                 null);
  265. };
  266.  
  267. /** 
  268.  * Deletes privacy sensitive data in a batch, optionally showing the 
  269.  * sanitize UI, according to user preferences
  270.  *
  271.  * @returns  null if everything's fine (no error or displayed UI,  which
  272.  *           should handle errors);  
  273.  *           an object in the form { itemName: error, ... } on (partial) failure
  274.  */
  275. Sanitizer.sanitize = function(aParentWindow) 
  276. {
  277.   if (Sanitizer.prefs.getBoolPref(Sanitizer.prefPrompt)) {
  278.     Sanitizer.showUI(aParentWindow);
  279.     return null;
  280.   }
  281.   return new Sanitizer().sanitize();
  282. };
  283.  
  284. Sanitizer.onStartup = function() 
  285. {
  286.   // we check for unclean exit with pending sanitization
  287.   Sanitizer._checkAndSanitize();
  288. };
  289.  
  290. Sanitizer.onShutdown = function() 
  291. {
  292.   // we check if sanitization is needed and perform it
  293.   Sanitizer._checkAndSanitize();
  294. };
  295.  
  296. // this is called on startup and shutdown, to perform pending sanitizations
  297. Sanitizer._checkAndSanitize = function() 
  298. {
  299.   const prefs = Sanitizer.prefs;
  300.   if (prefs.getBoolPref(Sanitizer.prefShutdown) && 
  301.       !prefs.prefHasUserValue(Sanitizer.prefDidShutdown)) {
  302.     // this is a shutdown or a startup after an unclean exit
  303.     Sanitizer.sanitize(null) || // sanitize() returns null on full success
  304.       prefs.setBoolPref(Sanitizer.prefDidShutdown, true);
  305.   }
  306. };
  307.  
  308.  
  309.